<?php
require './include/global.php';
require './include/validate.php';
require './include/all_left.php';
require_once './include/advisory_db.php';

if($_SESSION[usertype] != 'advisor' && $_SESSION['status'] != 'Premium') {
	redirect2("errorall.php?errid=rc_1016");
	exit;
}

//user type
$utype   = ($_SESSION[usertype]=='recruiter')?1:0;

//webinar id
$wb_id = $_GET[id];

$wb_title = $wb_id ? 'Edit a Webinar' : 'Create a Webinar';

if(!empty($_POST)&&$_POST[type]=='public'){
    $title      = htmlspecialchars(trim($_POST[title]));
	$description= htmlspecialchars(trim($_POST[description]));
	$host       = htmlspecialchars(trim($_POST[host]));
	$date       = htmlspecialchars(trim($_POST['date']));
	$email      = htmlspecialchars(trim($_POST['email']));
	$fullname   = htmlspecialchars(trim($_POST['fullname']));
	$fromhour   = htmlspecialchars(trim($_POST[fromhour]));
	$frommin    = htmlspecialchars(trim($_POST[frommin]));
	$fromam_pm  = htmlspecialchars(trim($_POST[fromam_pm]));
	$tohour     = htmlspecialchars(trim($_POST[tohour]));
	$tomin      = htmlspecialchars(trim($_POST[tomin]));
	$toam_pm    = htmlspecialchars(trim($_POST[toam_pm]));
	$timezone   = htmlspecialchars(trim($_POST[timezone]));
	$spoken     = htmlspecialchars(trim($_POST[spoken]));
	$pub        = @implode(",",$_POST[pub]);
	$active     = htmlspecialchars(trim($_POST[active]));
	$color      = htmlspecialchars(trim($_POST[color]));

	$sql_pub = "SELECT * FROM pa_webinar WHERE `wb_id`='".$wb_id."'";
	$pub_arr = $DB->fetch_one_array($sql_pub);
	if(empty($pub_arr)){
		$sql = "INSERT INTO `pa_webinar` (  `wb_uid` , `wb_uname` , `wb_fullname` , `wb_realname` , `wb_uemail` , `wb_utype` , `wb_date` , `wb_timezone` , `wb_starttime` , `wb_endtime` , `wb_topic`,`wb_description` , `wb_language` , `wb_selectpage` , `wb_host` , `wb_color` , `wb_status` )
	    VALUES ( '".$_SESSION[uid]."', '".$_SESSION[uname]."', '".$fullname."', '".$_SESSION['realname']."', '".$email."','".$utype."', '".$date."', '".$timezone."', '".$fromhour.$frommin.$fromam_pm."', '".$tohour.$tomin.$toam_pm."', '".$title."','".$description."', '".$spoken."', '".$pub."', '".$host."', '".$color."', '".$active."') ";
		$DB->query($sql);
		echo "<meta http-equiv=\"refresh\" content=\"0;URL=postwebinar.php?id=".$DB->insert_id()."\">";
		exit;
	}else{
		$sql = "UPDATE `pa_webinar` SET  `wb_fullname`='".$fullname."',`wb_uemail`='".$email."',`wb_utype`='".$utype."',`wb_date`='".$date."',`wb_timezone`='".$timezone."',`wb_starttime`='".$fromhour.$frommin.$fromam_pm."',`wb_endtime`='".$tohour.$tomin.$toam_pm."',`wb_topic`='".$title."',`wb_description`='".$description."',`wb_language`='".$spoken."',`wb_selectpage`='".$pub."',`wb_host`='".$host."',`wb_color`='".$color."',`wb_status`='".$active."' WHERE `wb_id`='".$wb_id."'";
	    $DB->query($sql);
	}
}

$sql_pub = "SELECT * FROM pa_webinar WHERE `wb_id`='".$wb_id."'";
$pub_arr = $DB->fetch_one_array($sql_pub);
//print_r($pub_arr);
if(!empty($pub_arr)){
	//print_r($pub_arr);
   $pub_arr[fromhour] = @substr($pub_arr[wb_starttime ],0,2);$pub_arr[frommin] = @substr($pub_arr[wb_starttime],2,2);$pub_arr[fromam_pm] = @substr($pub_arr[wb_starttime],4,2);
   $pub_arr[tohour] = @substr($pub_arr[wb_endtime],0,2);$pub_arr[tomin] = @substr($pub_arr[wb_endtime],2,2);$pub_arr[toam_pm] = @substr($pub_arr[wb_endtime],4,2);
   $pub_arr[page1] = (@ereg('1',$pub_arr['wb_selectpage']))?1:0;
   $pub_arr[page2] = (@ereg('2',$pub_arr['wb_selectpage']))?1:0;
   $pub_arr[page3] = (@ereg('3',$pub_arr['wb_selectpage']))?1:0;
   $pub_arr[page4] = (@ereg('4',$pub_arr['wb_selectpage']))?1:0;
   $smarty->assign('pub_action',"edit");
}else{
   $pub_arr['wb_host'] = 'http://';
}
$pub_arr[wb_color] = $pub_arr[wb_color] ? $pub_arr[wb_color] : 1;
$smarty->assign('pub', $pub_arr);
if(empty($pub_arr)) $smarty->assign("empty2",'1');



$smarty->assign('colors',array('1'=>'<img src="images/smallblock1.gif" border="0" width="10" style="margin:0;padding:0" />',
								'2'=>'<img src="images/smallblock2.gif" border="0" width="10" style="margin:0;padding:0" />',
								'3'=>'<img src="images/smallblock3.gif" border="0" width="10" style="margin:0;padding:0" />',
								'4'=>'<img src="images/smallblock4.gif" border="0" width="10" style="margin:0;padding:0" />'));

$smarty->assign('wb_title', $wb_title);
$smarty->assign('am_pm', $am_pm);
$smarty->assign('hours',array_slice($hours, 1, 12, true));
$smarty->assign('mins',$mins);
$smarty->assign('webinar_button_colors', $webinar_button_colors);

$smarty->compile_check = true;

$smarty->display('header.tpl');
$smarty->display('allleft.tpl');
$smarty->display('postwebinar.tpl');
$smarty->display('footer.tpl');


?>